package com.doit.day04

import scala.io.Source

class IteratorScalaDemo extends Iterator[ScalaHero]{

  private val lines: Iterator[String] = Source.fromFile("D:\\develop\\ideaWorkSpace\\myself\\Teach\\scala39\\src\\data\\Hero.txt").getLines()

  override def hasNext: Boolean = lines.hasNext

  override def next(): ScalaHero = {
    val res: String = lines.next()
    val arr: Array[String] = res.split("_")
    val arr1: Array[String] = arr(1).split(",")
    val arr2: Array[String] = arr1(1).split("::")
    ScalaHero(arr(0).toInt,arr1(0),arr2(0).toInt,arr2(1).toDouble)
  }
}

case class ScalaHero(id:Int,name:String,faceValue:Int,power:Double)


object IteratorScalaDemo1{
  def main(args: Array[String]): Unit = {
    val demo: IteratorScalaDemo = new IteratorScalaDemo
    while (demo.hasNext){
      println(demo.next())
    }
  }
}